package com.qiaotongtianxia.loans.adapters;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qiaotongtianxia.loans.R;
import com.qiaotongtianxia.loans.bean.Recommender;
import com.qiaotongtianxia.loans.util.CommonUtils;
import com.qiaotongtianxia.loans.views.BaseTextView;
import com.qiaotongtianxia.loans.views.refrushRecyclerView.BaseViewHolder;
import com.qiaotongtianxia.loans.views.refrushRecyclerView.RecyclerAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lisen on 2017/12/15.
 *
 * @author lisen < 4533548588@qq.com >
 */

public class RecommendAdapter extends RecyclerAdapter<Recommender> {

    private Context context;

    public RecommendAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder<Recommender> onCreateBaseViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_recommend, parent, false);
        return new Holder(view);
    }

    @SuppressWarnings("all")
    class Holder extends BaseViewHolder<Recommender> {

        @BindView(R.id.tv_status)
        BaseTextView tvStatus;
        @BindView(R.id.tv_name)
        BaseTextView tvName;
        @BindView(R.id.tv_phone)
        BaseTextView tvPhone;

        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(final Recommender data) {
            tvName.setText(data.getName());
            tvPhone.setText(data.getAccount());
            //1：已通过   2：待审核  3：驳回
            switch (CommonUtils.parseInt(data.getStatus())){
                case 1:
                    tvStatus.setText("成功借款"+data.getAmount()+"元");
                    tvStatus.setTextColor(ContextCompat.getColor(context,R.color.mainColor));
                    break;
                case 2:
                    tvStatus.setText("待审核");
                    tvStatus.setTextColor(ContextCompat.getColor(context,android.R.color.holo_orange_dark));
                    break;
                case 3:
                    tvStatus.setText("借款失败");
                    tvStatus.setTextColor(ContextCompat.getColor(context,R.color.darkRed));
                    break;
            }
        }
    }

}
